﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Finance.UI.Controllers;
using Finance.IBll;
using Finance.Bll;
using Finance.Entity;

namespace Finance.UI.Areas.FinanceManager.Controllers
{
    public class OrgController : AreaBaseController
    {
        //
        // GET: /FinanceManager/Org/
        IOrgBll orgBll = new OrgBll();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Save(string name, int id = 0)
        {
            bool success = orgBll.Save(id, name);
            return Json(new { success });
        }

        public ActionResult Delete(int id)
        {
            bool success = orgBll.Delete(id);
            return Json(new { success });
        }

        public ActionResult List(string name, int pageIndex = 1, int pageSize = 20)
        {
            var total = 0;
           IEnumerable<OrgEntity> orgList= orgBll.List(name, pageIndex, pageSize, out total);

           return Json(new { data=orgList,total});
        }

        public ActionResult ListAll()
        {

            IEnumerable<OrgEntity> orgList = orgBll.List();

            return Json(new {success=true, data = orgList });
        }
    }
}
